package practice;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 内存分配
 */
public class AssignMemory {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            List<Boolean> result = new ArrayList<>();
            Map<Integer, Integer> hashMap = Arrays.stream(sc.nextLine().split(","))
                    .map(s -> s.split(":"))
                    .collect(Collectors.toMap(strings -> Integer.parseInt(strings[0]), strings -> Integer.parseInt(strings[1])));
            Map<Integer, Integer> resources = new TreeMap<>(hashMap);
            int[] requests = Arrays.stream(sc.nextLine().split(","))
                    .mapToInt(Integer::parseInt)
                    .sorted()
                    .toArray();
            List<Integer> keyList = resources.keySet()
                    .stream()
                    .sorted()
                    .collect(Collectors.toList());
            for (int request: requests) {
                boolean isSuccess = assignMemory(request, keyList, resources);
                result.add(isSuccess);
            }
            String res = result.stream()
                    .map(Object::toString)
                    .collect(Collectors.joining(","));
            System.out.println(res);
        }
    }

    /**
     * 分配内存 将keyList排序后 找到第一个比applySize大的元素就返回分配成功
     * @param applySize
     * @param keyList
     * @param resources
     * @return
     */
    private static boolean assignMemory(int applySize,List<Integer> keyList,Map<Integer,Integer> resources) {
        for (Integer size : keyList) {
            if (size >= applySize) {
                Integer count = resources.getOrDefault(size, 0);
                if (count > 0) {
                    count--;
                    resources.put(size, count);
                    return true;
                }
            }
        }
        return false;
    }
}
